package com.dreamwhale.machinery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.entity.CarManage;
import com.dreamwhale.machinery.dao.CarManageMapper;
import com.dreamwhale.machinery.service.CarManageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 车辆入驻 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-08-04
 */
@Service
public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage> implements CarManageService {

    @Resource
    private CarManageMapper carManageMapper;

    @Override
    public int insertCarManages(CarManage carManage) {
        carManage.setCreateTime(LocalDateTime.now());
        return carManageMapper.insert(carManage);
    }

    @Override
    public int selectCarManageCount(String userId) {
        QueryWrapper<CarManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId).eq("car_audit", 1).eq("del_flag", 0);
        List<CarManage> list = carManageMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            return 1;
        }
        return 0;
    }
}
